//
//  TDNotificationDetailViewController.m
//  TFB
//
//  Created by yull on 15/8/15.
//  Copyright (c) 2015年 TD. All rights reserved.
//

#import "TDNotificationDetailViewController.h"

@interface TDNotificationDetailViewController ()

@end

@implementation TDNotificationDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"公告详情";
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self initSubviews];
    
//    self.contentview.layer.cornerRadius = 5;
//    self.contentview.layer.masksToBounds = YES;
    
    NSString *title = [self.noticeDic objectForKey:@"noticeTitle"];
    if (![title isKindOfClass:[NSString class]]) {
        title = @"--";
    }
    self.titleL.text = title;
    
    NSString *content = [self.noticeDic objectForKey:@"noticeBody"];
    if (![content isKindOfClass:[NSString class]]) {
        content = @"--";
    }
    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[content dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    self.contentL.attributedText = attrStr;
    [self.contentL sizeToFit];
//    CGRect frame = self.contentL.frame;
//    frame.size.height = frame.size.height < 54 ? 54 : frame.size.height;
//    self.contentL.frame = frame;
    
    NSString *time = [self.noticeDic objectForKey:@"createDate"];
    if (![time isKindOfClass:[NSString class]]) {
        time = @"--";
    } else {
        time = [NSString stringWithFormat:@"%@月%@日 %@:%@:%@",
                [time substringWithRange:NSMakeRange(4, 2)],
                [time substringWithRange:NSMakeRange(6, 2)],
                [time substringWithRange:NSMakeRange(8, 2)],
                [time substringWithRange:NSMakeRange(10, 2)],
                [time substringWithRange:NSMakeRange(12, 2)]];
    }
    self.timeL.text = time;
    
    CGRect frame = self.timeL.frame;
    frame.origin.y = CGRectGetMaxY(self.contentL.frame) + 3;
    self.timeL.frame = frame;
    
    frame = self.contentview.frame;
    frame.size.height = CGRectGetMaxY(self.timeL.frame) + 3;
    self.contentview.frame = frame;
    
    self.scrollview.contentSize = CGSizeMake(1, CGRectGetHeight(self.contentview.frame) + 20);
}

- (void)initSubviews
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:scrollView];
    self.scrollview = scrollView;
    
    UIView *contentview = [[UIView alloc] initWithFrame:CGRectMake(10, 10, scrollView.frame.size.width - 20, 0)];
    contentview.backgroundColor = [UIColor whiteColor];
    contentview.layer.cornerRadius = 5;
    contentview.layer.masksToBounds = YES;
    [scrollView addSubview:contentview];
    self.contentview = contentview;
    
    UILabel *titleL = [[UILabel alloc] initWithFrame:CGRectMake(8, 8, contentview.frame.size.width - 16, 22)];
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.font = [UIFont boldSystemFontOfSize:18];
    [contentview addSubview:titleL];
    self.titleL = titleL;
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(8, 30, contentview.frame.size.width - 16, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [contentview addSubview:lineView];
    
    UILabel *contentL = [[UILabel alloc] initWithFrame:CGRectMake(8, 33, contentview.frame.size.width - 16, 16)];
    contentL.numberOfLines = 0;
    contentL.font = [UIFont systemFontOfSize:14];
    [contentview addSubview:contentL];
    self.contentL = contentL;
    
    UILabel *timeL = [[UILabel alloc] initWithFrame:CGRectMake(8, CGRectGetMaxY(contentL.frame)  + 3, contentview.frame.size.width - 16, 20)];
    timeL.textColor = [UIColor grayColor];
    timeL.textAlignment = NSTextAlignmentRight;
    timeL.font = [UIFont systemFontOfSize:14];
    [contentview addSubview:timeL];
    self.timeL = timeL;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
}

@end
